package com.yuncheng.oaApi.lcService;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.constant.OaLogConstant;
import com.yuncheng.oaApi.constant.OaHysglOaFlowConstants;
import com.yuncheng.oaApi.constant.OaLgqsOaFlowConstants;
import com.yuncheng.oaApi.vo.AgentVo;
import com.yuncheng.oaApi.vo.OaFlowVo;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.Result;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import org.apache.commons.collections.CollectionUtils;
import com.yuncheng.oaApi.utils.GetUuIdUtils;;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.oaApi.busService.OaDbrService;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.oaApi.service.impl.OaYcSysUserServiceImpl;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.*;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import utils.DateConversionUtils;
import utils.LogUtils;
import utils.ObjectToMapUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Component(value = "OaHsyglFlowService")
public class OaHsyglOaFlowService extends OaFlowService {

    private static final Logger log = LoggerFactory.getLogger(OaHsyglOaFlowService.class);

    @Resource
    private IOaSpcySqsxJobService spcySqsxJobService;

    @Resource
    @Lazy
    private OaHysglOaFlowConstants oaHysglFlowConstant;

    @Resource
    @Lazy
    private OaYcSysUserServiceImpl ycSysUserService;

    @Resource
    @Lazy
    private IOaHysglService oaHysglService;

    @Resource
    @Lazy
    private ISpcyLogService spcyLogService;

    @Resource
    @Lazy
    private IOaSysTzMessageService sysTzMessageService;

    @Resource
    @Lazy
    private OaDbrService oaDbrService;

    @Resource
    @Lazy
    private IOaSpcyRsJjrkService oaSpcyRsJjrkService;

    public Result handleFlow(OaFlowVo oaFlowVo, OaJobEntity nowJob, String jobId, String oaid, String submitType, String opinion) {

        // 当前流程任务
        if (StringUtils.isNotBlank(jobId)) {
            nowJob = spcySqsxJobService.getById(jobId);
        }

        if (nowJob == null) {
            return Result.error("当前流程任务不存在，请重试");
        }
        if (StringUtils.isBlank(oaid)) {
            oaid = nowJob.getFpid();
        }

        if (StringUtils.isBlank(oaid)) {
            throw new BusinessException("参数丢失，请联系管理员");
        }


        // 提交按钮
        if (submitType.equals(OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT)) {
            if (nowJob == null) {
                return Result.error("当前流程任务不存在");
            }
        }
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser == null) {
            return Result.error("登录已失效，请重新登录");
        }
        OaHysgl byId = oaHysglService.getById(oaid);
        String timeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String name = currentUser.getName();
        String userId= currentUser.getId();
        YcSysUser ycSysUserById = ycSysUserService.getYcSysUserById(userId);

        //配置当前环节办理人和办理时间
      if (nowJob.getFhjmc().equals(OaHysglOaFlowConstants.HJMC_KSSP)) {
          byId.setFzbcsyjr(name);
          byId.setFzbcsyjsj(timeStr);
          byId.setFzbcsyjrks(currentUser.getDeptName());
          oaHysglService.updateById(byId);

      } else if (nowJob.getFhjmc().equals(OaHysglOaFlowConstants.HJMC_BGSSP)) {
          byId.setFbgsyjr(name);
          byId.setFbgsyjsj(timeStr);
          byId.setFbgsyjrks(currentUser.getDeptName());
          oaHysglService.updateById(byId);
        }
        // 流程环节处理
        Result httpResult = handleNodeName(oaFlowVo, submitType, nowJob, oaid, opinion);
        if (!httpResult.isSuccess()){
            return httpResult;
        }
        //最后一步状态标注流程结束
        /**
         * @Author: lhb
         * @Description :  是最后一步流程 且是 提交 才会判断为流程结束
         * @DateTime:
         * @Params:
         */
        if(nowJob.getFhjmc().equals(OaHysglOaFlowConstants.HJMC_HYAP) && submitType.equals(OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT)) {
            //当前流程id
            OaHysgl byIds = oaHysglService.getById(oaid);
            byIds.setFhyapr(name);
            byIds.setFhyapsj(timeStr);
            byIds.setFhyapks(currentUser.getDeptName());
            byIds.setFlczt(OaCommonFlowConstant.FLOW_LCJS);
            oaHysglService.updateById(byIds);

            //更新完成后在信息通知表里插入一条消息 表示未读
            sysTzMessageService.endMessage(oaid,false,true,false);

        }

        return Result.ok("操作成功");
    }

    public Result handleNodeName(OaFlowVo oaFlowVo, String submitType, OaJobEntity job, String oaId, String opinion){
        HashMap<String, Object> map = oaFlowVo.getMap();
        String dbrid = oaFlowVo.getDbrid();// 下环节待办人
        String smgflag = oaFlowVo.getSmgflag(); // 短信发送标志
        boolean isSubmit = true; // 是否提交流程
        Result res = null;

        // 保存按钮
        if (submitType.equals(OaCommonFlowConstant.SUBMIT_TYPE_SAVE)){
            updateSqsxJbxx(map,oaId,job);
        }

        // 提交按钮
        if (submitType.equals(OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT)){
            updateSqsxJbxx(map,oaId,job);

            // 流程任务id
            String jobId = "";
            if (job != null){
                jobId = job.getId();
            }

            String nextNode = "";
            if (StringUtils.isNotBlank(oaFlowVo.getNextNode())){
                nextNode = oaFlowVo.getNextNode();
            }

            // 提交流程任务,待办人是否为空，指定待办人
            if (isSubmit) {
                if (StringUtils.isBlank(dbrid)) {
                    // 提交-流程任务
                    res = this.passJob(oaId, jobId, opinion, nextNode, "");
                } else {
                    // 提交-流程任务
                    res = this.passJob(oaId, jobId, opinion, nextNode, dbrid);
                }
            }
            if (!res.isSuccess()){
                return res;
            }else {
                OaJobEntity nowJob = (OaJobEntity)res.getResult();
                // 接收返回的流程任务，如果返回的流程任务id不相等，发送短信
                if (nowJob != null && !jobId.equals(nowJob.getId()) && StringUtils.isNotBlank(smgflag) && smgflag.equals("是")){

                }
            }
        }
        return Result.ok("提交成功");
    }



    public Result updateSqsxJbxx(HashMap<String,Object> map, String oaid, OaJobEntity job){
        OaHysgl oldBasic = oaHysglService.getById(oaid);
        if (oldBasic == null){
            return Result.error("当前申请事项【"+oaid+"】不存在，请重试");
        }
        OaHysgl basicUpdate = null;
        basicUpdate = oldBasic;

        // 修改
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        try {
            BeanUtils.populate(basicUpdate,map);
            oaHysglService.updateById(basicUpdate);
        } catch (IllegalAccessException e) {
            log.error("出错-保存申请事项【非法访问异常】,{}",e.getMessage());
        } catch (InvocationTargetException e) {
            log.error("出错-保存申请事项【调用TargetException】,{}",e.getMessage());
        }

        String logContent = "基本信息修改: ";
        Map<String, Object> basicMap = ObjectToMapUtils.objectToMap(oldBasic);
        logContent += LogUtils.BeanModifyMsg(basicUpdate,basicMap);

        if (job == null) {
            spcyLogService.addLogs("null", logContent, oaid, OaCommonFlowConstant.LOGS_SYS_TYPE_XG, OaCommonFlowConstant.LOGS_SYS_TYPE_XG);
        } else {
            spcyLogService.addLogs(job.getFhjmc(), logContent, oaid, OaCommonFlowConstant.LOGS_SYS_TYPE_XG, OaCommonFlowConstant.LOGS_SYS_TYPE_XG);
        }

        return Result.ok("保存成功");
    }

    /**
     * 获取上一环节-通过业务分类编码
     *
     * @param ywflCode    业务分类编码
     * @param currentNode 当前环节
     * @return
     */
    private String getPreviousNodeByYwflcode(String ywflCode, String currentNode) {
        String preNode = "";

        if (ywflCode.equals(OaCommonFlowConstant.OA_HYSGL)) {
            preNode = oaHysglFlowConstant.getPreviousName(currentNode);
        }

        return preNode;
    }

    /**
     * 查询流程当前环节-上一环节
     * * @param jobid 流程任务id
     * * @param isZdhj 是否指定环节
     * * @return
     */
    public List<Map<String, String>> getCurrentJobPrevious(String jobid, boolean isZdhj) {
        if (StringUtils.isBlank(jobid)) {
            throw new BusinessException("流程任务参数为空！");
        }

        OaJobEntity currentJob = spcySqsxJobService.getById(jobid);
        if (currentJob == null) {
            throw new BusinessException("当前流程任务不存在！");
        }

        String fywflcode = "";
        String fpid = currentJob.getFpid(); // 关联业务id
        String flcmc = currentJob.getFlcmc(); // 所属流程
        String currentNode = currentJob.getFhjmc(); // 当前环节

        if (StringUtils.isBlank(flcmc)) {
            fywflcode = oaHysglFlowConstant.getFywflcode();

        } else {
            if (flcmc.equals(oaHysglFlowConstant.getFlowName())) {
                fywflcode = oaHysglFlowConstant.getFywflcode();
            }
        }

        List<Map<String, String>> ybNodeList = new ArrayList<>(); // 退回环节数组
        String previousNode = this.getPreviousNodeByYwflcode(fywflcode, currentNode); // 上一环节

        // 指定环节
        if (isZdhj) {
            List<OaJobEntity> preJobList = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                    .eq(OaJobEntity::getFpid, fpid)
                    .eq(OaJobEntity::getFblzt, OaCommonFlowConstant.BLZT_YB)
                    .eq(OaJobEntity::getFlcmc, flcmc)
                    .orderByAsc(OaJobEntity::getFfssj));
            if (CollectionUtils.isNotEmpty(preJobList)) {
                for (OaJobEntity job : preJobList) {

                    // 判断是否存在一样的环节名称，存在跳出当次循环
                    boolean isExistNode = false;
                    if (CollectionUtils.isNotEmpty(ybNodeList)) {
                        for (Map<String, String> disMap : ybNodeList) {
                            if (disMap.get("fhjmc").equals(job.getFhjmc())) {
                                isExistNode = true;
                                break;
                            }
                        }
                    }
                    if (isExistNode) {
                        continue;
                    }
                    Map<String, String> map = new HashMap<>();
                    map.put("id", job.getId());
                    map.put("fhjmc", job.getFhjmc());
                    ybNodeList.add(map);
                }
            }
        } else {
            // 查询上一环节是否存在
            List<OaJobEntity> preJobList = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                    .eq(OaJobEntity::getFpid, fpid)
                    .eq(OaJobEntity::getFhjmc, previousNode)
                    .eq(OaJobEntity::getFblzt, OaCommonFlowConstant.BLZT_YB)
                    .eq(OaJobEntity::getFlcmc, flcmc)
                    .orderByDesc(OaJobEntity::getFfssj));

            if (CollectionUtils.isNotEmpty(preJobList)) {
                Map<String, String> map = new HashMap<>();
                map.put("id", preJobList.get(0).getId());
                map.put("fhjmc", preJobList.get(0).getFhjmc());
                ybNodeList.add(map);
            }
        }
        return ybNodeList;
    }

    /**
     * 获取oa-流转记录
     */
    public List<OaJobEntity> getJobListByOaId(String oaid) {
        LambdaQueryWrapper<OaJobEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(OaJobEntity::getFlcmc, oaHysglFlowConstant.getFlowName());
        queryWrapper.eq(OaJobEntity::getFpid, oaid);
        queryWrapper.orderByAsc(OaJobEntity::getCreateTime);
        queryWrapper.orderByAsc(OaJobEntity::getFfssj);
        List<OaJobEntity> jobList = spcySqsxJobService.list(queryWrapper);

        return jobList;
    }

    /**
     * 退回流程 - 指定环节
     */
    public void returnZdJob(OaReturnVo oaReturnVo) {
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser == null) {
            throw new BusinessException("登录已失效，请重新登录！");
        }

        if (StringUtils.isBlank(oaReturnVo.getJobid())) {
            throw new BusinessException("流程任务参数为空！");
        }

        if (StringUtils.isBlank(oaReturnVo.getOpinion())) {
            throw new BusinessException("请填写退回意见！");
        }

        if (StringUtils.isBlank(oaReturnVo.getShjid())) {
            throw new BusinessException("请选择退回环节！");
        }

        // 当前环节
        OaJobEntity currentJob = spcySqsxJobService.getById(oaReturnVo.getJobid());
        if (currentJob == null) {
            throw new BusinessException("当前流程任务不存在！");
        }

        String sqsxid = currentJob.getFpid();
        String oldfhjmc = currentJob.getFhjmc();


        // 上一环节
        OaJobEntity previousJob = spcySqsxJobService.getById(oaReturnVo.getShjid());
        if (currentJob == null) {
            throw new BusinessException("当前流程任务不存在！");
        }
        String previousNode = previousJob.getFhjmc();

        String bllx = "[" + oldfhjmc + "]" + OaCommonFlowConstant.BLLX_TH + "[" + previousNode + "]";
        Result result = this.doJob(currentJob, currentUser, oaReturnVo.getOpinion(), bllx);
        if (!result.isSuccess()) {
            throw new BusinessException(result.getMessage());
        }

        /**
         * 创建退回环节流程任务
         */
        OaJobEntity newPreviousJob = new OaJobEntity();
        BeanUtil.copyProperties(previousJob, newPreviousJob);
        newPreviousJob.setId(GetUuIdUtils.NotReplaceUuId());

        if (StringUtils.isBlank(newPreviousJob.getFpid())) {
            newPreviousJob.setFpid(sqsxid);
        }


        newPreviousJob.setFblzt(OaCommonFlowConstant.BLZT_TH);
        newPreviousJob.setFlcmc(OaHysglOaFlowConstants.LCMC_LIKE_OALC);
        newPreviousJob.setFthyj(oaReturnVo.getOpinion());
        newPreviousJob.setFblyj("");
        newPreviousJob.setFblr("");
        newPreviousJob.setFblsj(null);
        newPreviousJob.setFblbm("");
        newPreviousJob.setFbllx(bllx);
        newPreviousJob.setFfssj(new Date());
        newPreviousJob.setFfsrid(currentUser.getId());
        newPreviousJob.setFfsrmc(currentUser.getName());
        spcySqsxJobService.save(newPreviousJob);
        //处理主表数据
        OaHysgl oaHysgl = oaHysglService.getById(sqsxid);
        if (previousNode.equals(OaHysglOaFlowConstants.HJMC_SQ)) {
            oaHysgl.setFzbcsyj("");
            oaHysgl.setFzbcsyjr("");
            oaHysgl.setFzbcsyjrks("");
            oaHysgl.setFzbcsyjsj("");
            oaHysgl.setFbgsyj("");
            oaHysgl.setFbgsyjr("");
            oaHysgl.setFbgsyjrks("");
            oaHysgl.setFbgsyjsj("");
            oaHysgl.setFhyapr("");
            oaHysgl.setFhyapsj("");
            oaHysgl.setFhyapyj("");
            oaHysgl.setFhyapks("");
            oaHysgl.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        } else if (previousNode.equals(OaHysglOaFlowConstants.HJMC_KSSP)) {
            oaHysgl.setFbgsyj("");
            oaHysgl.setFbgsyjr("");
            oaHysgl.setFbgsyjrks("");
            oaHysgl.setFbgsyjsj("");
            oaHysgl.setFhyapr("");
            oaHysgl.setFhyapsj("");
            oaHysgl.setFhyapyj("");
            oaHysgl.setFhyapks("");

            oaHysgl.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        } else if (previousNode.equals(OaHysglOaFlowConstants.HJMC_BGSSP)) {
            oaHysgl.setFhyapr("");
            oaHysgl.setFhyapsj("");
            oaHysgl.setFhyapyj("");
            oaHysgl.setFhyapks("");

            oaHysgl.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        } else {

            oaHysgl.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        }
        oaHysglService.updateById(oaHysgl);


    }

    /**
     * 办理环节
     *
     * @param job         当前流程任务
     * @param currentUser 当前用户
     * @param opinion     意见
     * @param returnNode  退回环节
     */
    private Result doJob(OaJobEntity job, CurrentUserVo currentUser, String opinion, String returnNode) {
        String blrId = "";
        String blr = "";
        String blbm = "";
        if (currentUser != null) {
            blrId = currentUser.getId();
            blr = currentUser.getName();
            blbm = currentUser.getOrgName();
        }
        if (job == null) {
            return Result.error("当前流程任务不存在，请重试");
        }
//        if(CommonFlowConstant.BLZT_YB.equals(job.getFblzt())){
//            return Result.error("当前任务已提交");
//        }
        if (StringUtils.isBlank(job.getFdbrid())) {
            return Result.error("当前任务未指定办理人");
        }
//        if(!job.getFdbrid().contains(blrId)){
//            return Result.error("当前登录用户无此任务的办理权限");
//        }
        // 办理方式 竞争办理 、多人线性办理 、多人并行办理
        String blfs = job.getFblfs();
        if (StringUtils.isBlank(blfs) || blfs.equals(OaCommonFlowConstant.BLFS_DRJJ)) {
            job.setFblr(blr);
            job.setFblsj(new Date());
            job.setFblyj(opinion);
            job.setFblzt(OaCommonFlowConstant.BLZT_YB);
            if (StringUtils.isBlank(returnNode)) {
                job.setFbllx(OaCommonFlowConstant.BLLX_BL);
            } else {
                job.setFbllx(returnNode);
            }
            job.setFblbm(blbm);

            // 审评查验流程 计算 办理天数、是否超时
            /*if (StringUtils.isNotBlank(job.getFlcmc()) && job.getFlcmc().contains(YpscFlowConstant.LCMC_LIKE_SPCYLC)) {
                job.setFsyts(flowJobBlsxService.jsTwoDateBetweenDays(job.getFksyts(),job.getFpid(),job.getFfssj(), job.getFblsj(), job.getFztkssj(),job.getFztjssj())); // 使用天数
                job.setFsfcs(flowJobBlsxService.isDateBetweenSfcs(job.getFsyts(), job.getFcnts())); // 办理是否超时
            }*/

            spcySqsxJobService.updateById(job);
            return Result.ok(job);
        } else if (blfs.equals(OaCommonFlowConstant.BLFS_DRXX) || blfs.equals(OaCommonFlowConstant.BLFS_DRBX)) {
            //先根据多个人线性和多人并行的逻辑获得下一办理人
            String nextBlrId = "";
            String nextBlr = "";
            if (blfs.equals(OaCommonFlowConstant.BLFS_DRXX)) {
                String ydbrIds[] = job.getFydbrid().split(",");
                String ydbrs[] = job.getFydbr().split(",");
                for (int i = 0; i < ydbrIds.length; i++) {
                    String dbrId = ydbrIds[i];
                    //不考虑办理人id重复出现（一个人办多次）的情况
                    if (dbrId.equals(blrId)) {
                        if (i + 1 < ydbrIds.length) {
                            nextBlrId = ydbrIds[i + 1];
                            nextBlr = ydbrs[i + 1];
                            break;
                        }
                    }
                }
            } else {
                String dbrIds[] = job.getFdbrid().split(",");
                String dbrs[] = job.getFdbr().split(",");
                for (int i = 0; i < dbrIds.length; i++) {
                    String dbrId = dbrIds[i];
                    String dbr = dbrs[i];
                    //不考虑办理人id重复出现（一个人办多次）的情况
                    if (!dbrId.equals(blrId)) {
                        nextBlrId = nextBlrId + (StringUtils.isBlank(nextBlrId) ? "" : ",") + dbrId;
                        nextBlr = nextBlr + (StringUtils.isBlank(nextBlr) ? "" : ",") + dbr;
                    }
                }
            }

            //如果存在下一办理人 就继续待办，多人办理意见用@@分隔，办理时间、办理人、意见 用|分隔
            job.setFblr(blr);
            job.setFblsj(new Date());
            String blyj = (job.getFblyj() == null ? "" : job.getFblyj()) + (StringUtils.isBlank(job.getFblyj()) ? "" : "@@") + DateConversionUtils.DateToString(new Date()) + "|" + blr + "|" + opinion;
            job.setFblyj(blyj);
            if (StringUtils.isBlank(nextBlrId)) {
                job.setFblzt(OaCommonFlowConstant.BLZT_YB);
                if (StringUtils.isBlank(returnNode)) {
                    job.setFbllx(OaCommonFlowConstant.BLLX_BL);
                } else {
                    job.setFbllx(returnNode);
                }
                job.setFblbm(blbm);
            } else {
                job.setFblzt(OaCommonFlowConstant.BLZT_DB);
                job.setFdbrid(nextBlrId);
                job.setFdbr(nextBlr);
            }
            spcySqsxJobService.updateById(job);
            return Result.ok(job);
        }
        return Result.error("待办任务未指定办理方式");
    }


    /**
     * @Author:
     * @Description : 退回流程
     * @DateTime:
     * @Params:
     */
    public Result getReturnUpperFlowJob(String jobid, String opinion) {
        if (StringUtils.isBlank(jobid)) {
            return Result.error("当前流程任务id不能为空");
        }
        OaJobEntity job = spcySqsxJobService.getById(jobid);
        if (job == null){
            return Result.error("当前流程任务不存在");
        }
        // 办理状态 - 待办
        if (StringUtils.isNotBlank(job.getFblzt()) && (job.getFblzt().equals(OaCommonFlowConstant.BLZT_DB) || job.getFblzt().equals(OaCommonFlowConstant.BLZT_TH))){
            // 待办-获取上一个环节id
            String fsyhjid = job.getFsyhjid();
            OaJobEntity syhjJob = spcySqsxJobService.getById(fsyhjid);
            if (syhjJob != null){
                syhjJob.setFthyj(opinion);
                syhjJob.setFfssj(new Date());
                syhjJob.setFblzt(OaCommonFlowConstant.BLZT_TH);
                syhjJob.setFblr("");
                syhjJob.setFblyj("");
                syhjJob.setFblbm("");
                spcySqsxJobService.updateById(syhjJob);

                spcySqsxJobService.removeById(jobid); // 删除当前流程任务待办
            }
        }
        String logNr = "退回上一环节: ";
        Map<String, Object> map = ObjectToMapUtils.objectToMap(job);
        logNr += LogUtils.MapToStringMethod(map);
        spcyLogService.addLogs(job.getFhjmc(),logNr,job.getFpid(), OaLogConstant.LOGS_SQSX_JOB, OaCommonFlowConstant.LOGS_SYS_TYPE_TH);
        return Result.ok("success");
    }

    /**
     * 获取当前流程任务相关信息
     * @param jobid 流程任务id
     */
    public Map getJobConcernByJobId(String jobid){
        Map map = new HashMap();

        // 当前流转记录
        OaJobEntity job = spcySqsxJobService.getById(jobid);
        if (job == null){
            log.error("当前流程任务id为【{}】的流转记录不存在",jobid);
            return map;
        }
        String oaid = job.getFpid();
        if (org.apache.commons.lang3.StringUtils.isBlank(oaid)){
            log.error("当前流程任务id为【{}】的流转记录中的申请事项id为空",jobid);
            return map;
        }

        // oaid事项基本信息
        OaHysgl sqsxBasic = oaHysglService.getById(oaid);

        // 流程任务流传记录
        List<OaJobEntity> jobList = this.getJobListBySqsxId(oaid);

//        // 申请事项相关文件记录
//        List<SpcySqsxWjjl> wjjlList = busService.getWjjlListBySqsxId(oaid);

        // 申请事项的检查项目
//        List<SpcySqsxJcxm> jcxmList = getJcxmQxListBySqsxId(sqsxBasic);



        // 获取下环节待办人
        String nextNode = oaHysglFlowConstant.getNextNodeName(job.getFhjmc());
        Map nextDbr = this.getNodeDbr(oaid, nextNode,"");
        List<AgentVo> dbrListByMap = oaDbrService.getDbrListByMap(nextDbr);

        map.put("sqsx",sqsxBasic); // 申请事项基本信息
        map.put("job",job); // 当前流转记录
        map.put("jobHistoryList",jobList); // 流程任务流传记录
//        map.put("wjjlList",wjjlList); // 申请事项-相关文件

        map.put("nextNodeDbrList",dbrListByMap); // 下环节待办人list
        map.put("nextNode",nextNode);

        return map;
    }

    /**
     * 获取申请事项-流转记录
     */
    public List<OaJobEntity> getJobListBySqsxId(String oaid){
        LambdaQueryWrapper<OaJobEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(OaJobEntity::getFlcmc, oaHysglFlowConstant.getFlowName());
        queryWrapper.eq(OaJobEntity::getFpid, oaid);
        queryWrapper.orderByAsc(OaJobEntity::getCreateTime);
        queryWrapper.orderByAsc(OaJobEntity::getFfssj);
        List<OaJobEntity> jobList = spcySqsxJobService.list(queryWrapper);

        return jobList;
    }



    //初始化任务
    public Result initJob(String oaId, CurrentUserVo currentUser){
        String nodeName = oaHysglFlowConstant.getFirstNode();
        //需要校验是否已经初始化过
        List<OaJobEntity> list = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                .eq(OaJobEntity::getFpid, oaId)
                .eq(OaJobEntity::getFhjmc, nodeName)
                .eq(OaJobEntity::getFlcmc, oaHysglFlowConstant.getFlowName())
        );
        if(list.size()>0){
            return Result.ok(list.get(0));

        }
        return this.initJob(oaHysglFlowConstant,oaId,currentUser);
    }

    /**
     * 提交当前环节的待办记录
     *  @param oaId  oa-id
     *  @param jobId 当前环节id
     *  @param opinion 办理意见
     */
    public Result passJob(String oaId, String jobId, String opinion,String nextNodeName,String nextNodeDbrIds){
        //处理业务表的逻辑
        Result httpResult = this.passJob(oaHysglFlowConstant, oaId, jobId, opinion, nextNodeName, nextNodeDbrIds);
        return httpResult;
    }

    /**
     *
     * @param job
     * @param currentUser
     */
    private Result doJob(OaJobEntity job, CurrentUserVo currentUser, String opinion){
        String blrId = "";
        String blr = "";
        if (currentUser != null) {
            blrId = currentUser.getId();
            blr = currentUser.getName();
        }
        if (job == null){
            return Result.error("当前流程任务不存在，请重试");
        }
        if(OaCommonFlowConstant.BLZT_YB.equals(job.getFblzt())){
            return Result.error("当前任务已提交");
        }
        if(StringUtils.isBlank(job.getFdbrid())){
            return Result.error("当前任务未指定办理人");
        }
        if(!job.getFdbrid().contains(blrId)){
            return Result.error("当前登录用户无此任务的办理权限");
        }
        // 办理方式  、多人竞争办理
        String blfs = job.getFblfs();
        if(StringUtils.isBlank(blfs)||blfs.equals(OaCommonFlowConstant.BLFS_DRJJ)){
            job.setFblr(blr);
            job.setFblsj(new Date());
            job.setFblyj(opinion);
            job.setFblzt(OaCommonFlowConstant.BLZT_YB);
            spcySqsxJobService.updateById(job);
            return Result.ok(job);
        }else if(blfs.equals(OaCommonFlowConstant.BLFS_DRXX)  || blfs.equals(OaCommonFlowConstant.BLFS_DRBX)){
            //先根据多个人线性和多人并行的逻辑获得下一办理人
            String nextBlrId ="";
            String nextBlr ="";
            if(blfs.equals(OaCommonFlowConstant.BLFS_DRXX)){
                String ydbrIds[] = job.getFydbrid().split(",");
                String ydbrs[] = job.getFydbr().split(",");
                for (int i=0;i<ydbrIds.length;i++){
                    String dbrId = ydbrIds[i];
                    //不考虑办理人id重复出现（一个人办多次）的情况
                    if(dbrId.equals(blrId)){
                        if(i+1<ydbrIds.length){
                            nextBlrId=ydbrIds[i+1];
                            nextBlr=ydbrs[i+1];
                            break;
                        }
                    }
                }
            }else{
                String dbrIds[] = job.getFdbrid().split(",");
                String dbrs[] = job.getFdbr().split(",");
                for (int i=0;i<dbrIds.length;i++){
                    String dbrId = dbrIds[i];
                    String dbr = dbrs[i];
                    //不考虑办理人id重复出现（一个人办多次）的情况
                    if(!dbrId.equals(blrId)){
                        nextBlrId=nextBlrId+(StringUtils.isBlank(nextBlrId)?"":",")+dbrId;
                        nextBlr=nextBlr+(StringUtils.isBlank(nextBlr)?"":",")+dbr;
                    }
                }
            }

            //如果存在下一办理人 就继续待办，多人办理意见用@@分隔，办理时间、办理人、意见 用|分隔
            job.setFblr(blr);
            job.setFblsj(new Date());
            String blyj=(job.getFblyj()==null?"":job.getFblyj())+(StringUtils.isBlank(job.getFblyj())?"":"@@")+ DateConversionUtils.DateToString(new Date()) +"|"+blr+"|"+ opinion;
            job.setFblyj(blyj);
            if(StringUtils.isBlank(nextBlrId)){
                job.setFblzt(OaCommonFlowConstant.BLZT_YB);
            }else{
                job.setFblzt(OaCommonFlowConstant.BLZT_DB);
                job.setFdbrid(nextBlrId);
                job.setFdbr(nextBlr);
            }
            spcySqsxJobService.updateById(job);
            return Result.ok(job);
        }
        return Result.error("待办任务未指定办理方式");
    }

    /**
     *
     * @param oaId
     * @param currentJob
     * @param currentUser
     * @param nextNodeName
     * @param nextNodeDbrIds
     * @return
     */
    public Result createNextJob(String oaId, OaJobEntity currentJob, CurrentUserVo currentUser, String nextNodeName, String nextNodeDbrIds){
        if (currentJob != null) {
            nextNodeName = getNextNodeName(currentJob.getFhjmc(), nextNodeName);
        }else {
            if (StringUtils.isBlank(nextNodeName)){
                return Result.error("下环节不能为空");
            }
        }
        if(nextNodeName.equals(OaLgqsOaFlowConstants.HJMC_LCJS)){
            OaJobEntity job = new OaJobEntity();

            return Result.ok("操作成功");
        }
        Map map = this.getNodeDbr(oaId,nextNodeName,nextNodeDbrIds);
        nextNodeDbrIds = map.get("dbrId").toString();
        String nextNodeDbrs = map.get("dbr").toString();
        if(StringUtils.isBlank(nextNodeDbrIds)){
            return Result.error("获取不到下一环节待办人");
        }
        OaJobEntity job = new OaJobEntity();
        job.setId(GetUuIdUtils.generateUuid());
        if(currentJob != null){
            job.setFsyhjid(currentJob.getId());
        }
        job.setFpid(oaId);
        job.setFhjmc(nextNodeName);
        if (currentUser != null) {
            job.setFfsrid(currentUser.getId());
            job.setFfsrmc(currentUser.getName());
        }
        job.setFfssj(new Date());

        job.setFdbrid(nextNodeDbrIds);
        job.setFdbr(nextNodeDbrs);
        job.setFydbrid(nextNodeDbrIds);
        job.setFydbr(nextNodeDbrs);

        // job.setFblfs(YpzcFlowConstant.getBlfs(nextNodeName));
        job.setFblzt(OaCommonFlowConstant.BLZT_DB);
        spcySqsxJobService.save(job);
        return Result.ok(job);
    }


    /**
     * @param:
     * @Description: 创建第一个环节
     * @auther: lhb
     * @date: 2023/9/9 18:09
     */
    public Result createSqJob(String jobid, String oaId, String opinion) {
        OaJobEntity byId = spcySqsxJobService.getById(jobid);
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();

        String old = byId.getFhjmc();
        String fhjmc = OaHysglOaFlowConstants.HJMC_SQ;
        String fpid = oaId;
        List<OaJobEntity> previousJob = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                .eq(OaJobEntity::getFpid, fpid)
                .eq(OaJobEntity::getFhjmc, fhjmc));
//        System.out.println(previousJob);

        String fdbr = previousJob.get(0).getFdbr();
        String fdbrid = previousJob.get(0).getFdbrid();


        /**
         * 创建退回环节流程任务
         */
        OaJobEntity newPreviousJob = new OaJobEntity();

        newPreviousJob.setId(GetUuIdUtils.NotReplaceUuId());
        if (StringUtils.isBlank(newPreviousJob.getFpid())) {
            newPreviousJob.setFpid(oaId);
        }
        newPreviousJob.setFdbr(fdbr);
        newPreviousJob.setFdbrid(fdbrid);

        newPreviousJob.setFlcmc(OaHysglOaFlowConstants.LCMC_LIKE_OALC);
        newPreviousJob.setFhjmc(fhjmc);
        newPreviousJob.setFthyj(opinion);
        newPreviousJob.setFbllx(OaCommonFlowConstant.BLLX_DB);
        newPreviousJob.setFblzt(OaCommonFlowConstant.BLZT_TH);
        newPreviousJob.setFblyj("");
        newPreviousJob.setFblr("");
        newPreviousJob.setFblsj(null);
        newPreviousJob.setFblbm("");
        newPreviousJob.setFbllx("[" + old + "]" + "退回" + "[" + fhjmc + "]");
        newPreviousJob.setFfssj(new Date());
        newPreviousJob.setFfsrid(currentUser.getId());
        newPreviousJob.setFfsrmc(currentUser.getName());
        newPreviousJob.setFsyhjid("");
        newPreviousJob.setFblbm(currentUser.getDeptName());
        newPreviousJob.setFblfs(OaCommonFlowConstant.BLFS_DRJJ);

        spcySqsxJobService.save(newPreviousJob);
        OaHysgl oaHysgl = oaHysglService.getById(oaId);
        oaHysgl.setFzbcsyj("");
        oaHysgl.setFzbcsyjr("");
        oaHysgl.setFzbcsyjrks("");
        oaHysgl.setFzbcsyjsj("");
        oaHysgl.setFbgsyj("");
        oaHysgl.setFbgsyjr("");
        oaHysgl.setFbgsyjrks("");
        oaHysgl.setFbgsyjsj("");
        oaHysgl.setFhyapr("");
        oaHysgl.setFhyapsj("");
        oaHysgl.setFhyapyj("");
        oaHysgl.setFhyapks("");
        oaHysglService.updateById(oaHysgl);


        return Result.ok(newPreviousJob);


    }

    /**
     * @param job
     * @Description 提交当前环节
     */
    public Result doJobs(String job, String opinion) {
        OaJobEntity byId = spcySqsxJobService.getById(job);
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String blrId = "";
        String blr = "";
        if (currentUser != null) {
            blrId = currentUser.getId();
            blr = currentUser.getName();
        }
        if (job == null) {
            return Result.error("当前流程任务不存在，请重试");
        }
        if (OaCommonFlowConstant.BLZT_YB.equals(byId.getFblzt())) {
            return Result.error("当前任务已提交");
        }
//        if(StringUtils.isBlank(job.getFdbrid())){
//            return Result.error("当前任务未指定办理人");
//        }
        if (!byId.getFdbrid().contains(blrId)) {
            return Result.error("当前登录用户无此任务的办理权限");
        }
        // 办理方式  、多人竞争办理
        String blfs = byId.getFblfs();
        if (StringUtils.isBlank(blfs) || blfs.equals(OaCommonFlowConstant.BLFS_DRJJ)) {
            byId.setFblr(blr);
            byId.setFblsj(new Date());
            byId.setFblyj(opinion);
            byId.setFblzt(OaCommonFlowConstant.BLZT_YB);
            spcySqsxJobService.updateById(byId);
            return Result.ok(job);
        } else if (blfs.equals(OaCommonFlowConstant.BLFS_DRXX) || blfs.equals(OaCommonFlowConstant.BLFS_DRBX)) {
            //先根据多个人线性和多人并行的逻辑获得下一办理人
            String nextBlrId = "";
            String nextBlr = "";
            if (blfs.equals(OaCommonFlowConstant.BLFS_DRXX)) {
                String ydbrIds[] = byId.getFydbrid().split(",");
                String ydbrs[] = byId.getFydbr().split(",");
                for (int i = 0; i < ydbrIds.length; i++) {
                    String dbrId = ydbrIds[i];
                    //不考虑办理人id重复出现（一个人办多次）的情况
                    if (dbrId.equals(blrId)) {
                        if (i + 1 < ydbrIds.length) {
                            nextBlrId = ydbrIds[i + 1];
                            nextBlr = ydbrs[i + 1];
                            break;
                        }
                    }
                }
            } else {
                String dbrIds[] = byId.getFdbrid().split(",");
                String dbrs[] = byId.getFdbr().split(",");
                for (int i = 0; i < dbrIds.length; i++) {
                    String dbrId = dbrIds[i];
                    String dbr = dbrs[i];
                    //不考虑办理人id重复出现（一个人办多次）的情况
                    if (!dbrId.equals(blrId)) {
                        nextBlrId = nextBlrId + (StringUtils.isBlank(nextBlrId) ? "" : ",") + dbrId;
                        nextBlr = nextBlr + (StringUtils.isBlank(nextBlr) ? "" : ",") + dbr;
                    }
                }
            }

            //如果存在下一办理人 就继续待办，多人办理意见用@@分隔，办理时间、办理人、意见 用|分隔
            byId.setFblr(blr);
            byId.setFblsj(new Date());
            String blyj = (byId.getFblyj() == null ? "" : byId.getFblyj()) + (StringUtils.isBlank(byId.getFblyj()) ? "" : "@@") + DateConversionUtils.DateToString(new Date()) + "|" + blr + "|" + opinion;
            byId.setFblyj(blyj);
            if (StringUtils.isBlank(nextBlrId)) {
                byId.setFblzt(OaCommonFlowConstant.BLZT_YB);
            } else {
                byId.setFblzt(OaCommonFlowConstant.BLZT_DB);
                byId.setFdbrid(nextBlrId);
                byId.setFdbr(nextBlr);
            }
            spcySqsxJobService.updateById(byId);
            return Result.ok(job);
        }
        return Result.error("待办任务未指定办理方式");
    }


    /**
     * @param currentNodeName 可为空(如果为空，nextNodeName不为空)
     * @param nextNodeName    可为空(如果为空，currentNodename不为空)
     * @return
     */
    private String getNextNodeName(String currentNodeName, String nextNodeName) {
        if (StringUtils.isNotBlank(nextNodeName)) {
            return nextNodeName;
        }else{
            return oaHysglFlowConstant.getNextNodeName(currentNodeName);
        }
    }

    // 获取当前环节待办人
    public Map getNodeDbr(String oaid,String nodeName, String dbrIds){
        Map map = new HashMap();
        String dbrId = "";
        String dbr = "";
        if(StringUtils.isNotBlank(dbrIds)){
            dbr = oaDbrService.getDbrsByIds(dbrIds);
            dbrId = dbrIds;
        }else{
            // 申请
            if (nodeName.equals(OaHysglOaFlowConstants.HJMC_SQ)){
                // 本人提交
                CurrentUserVo user = ThreadContextHelper.getCurrentUser(); //当前用户信息
                if (user == null){
                    throw new BusinessException("没有登录信息");
                }
                String id = user.getId();
                String name = user.getName();
                dbrId = id;
                dbr = name;
            }
            // 科室审批
            if (nodeName.equals(OaHysglOaFlowConstants.HJMC_KSSP)){
                // 科室负责人
                OaHysgl oaids = oaHysglService.getById(oaid);
                Map kzMap = oaDbrService.getKsfzrByDeptName(oaids.getFsyks());
                dbrId = kzMap.get("dbrId").toString();
                dbr = kzMap.get("dbr").toString();
            }
            // 办公室审批
            if (nodeName.equals(OaHysglOaFlowConstants.HJMC_BGSSP)) {
                // 办公室科室负责人

                Map kzMap = oaDbrService.getKsfzrByDeptName(OaCommonFlowConstant.BGS_SP_FLOW);
                dbrId = kzMap.get("dbrId").toString();
                dbr = kzMap.get("dbr").toString();
            }
            // 会议安排
            if (nodeName.equals(OaHysglOaFlowConstants.HJMC_HYAP)) {
                // 会议安排负责人 梁爽
                Map kzMap = oaDbrService.gethyapFzrByDeptName();
                dbrId = kzMap.get("dbrId").toString();
                dbr = kzMap.get("dbr").toString();
            }
        }
        map.put("dbrId",dbrId);
        map.put("dbr",dbr);
        return map;
    }

    // 获取当前环节待办人
    public Map getNodeDbr(String nodeName, String dbrIds){
        return this.getNodeDbr(null,nodeName,dbrIds);
    }


    //判断当前会议地点是否重复申请
    public Boolean sfHydd(String hydd,String fhykssj,String fhyjssj){
        List<OaHysgl> oaHysglList = oaHysglService.list(new LambdaQueryWrapper<OaHysgl>().eq(OaHysgl::getFhydd, hydd)
                                                             .eq(OaHysgl::getFlczt, OaCommonFlowConstant.FLOW_LCZB));

        boolean sfcd = false;

        //接收的传入时间字符串
        String t3 = fhykssj;
        String t4 = fhyjssj;
        if (CollectionUtil.isNotEmpty(oaHysglList)){
            try {
                  for (OaHysgl hysgl : oaHysglList) {
                        //被比较的时间
//            String BjFhykssj = hysgl.getFhykssj(); //数据库中的会议开始时间
//            String BjFhyjssj = hysgl.getFhyjssj(); //数据库中会议结束时间

                        //需要比较的时间
                        String t1 = hysgl.getFhykssj(); //数据库中的会议开始时间
                        String t2 = hysgl.getFhyjssj(); //数据库中会议结束时间

                        DateFormat d_Fm = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //格式化 时间格式

                        Date T1 = d_Fm.parse(t1);
                        Date T2 = d_Fm.parse(t2);
                        Date T3 = d_Fm.parse(t3);
                        Date T4 = d_Fm.parse(t4);
                    if ((
                            //T1-T2为第一个时间段  T3-T4为第二个时间段
                            //判断第一种情况，第二个时间段的结束时间T4在第一个时间段（T1-T2）内
//                          T1------T2
//                     T3--------t4
                            T3.getTime() <= T1.getTime() && T4.getTime() >= T1.getTime()) ||
                            //判断第二种情况，第二个时间段的开始时间T3在第一个时间段（T1-T2）内
//                     T1------T2
//                          T3--------t4
                            (T3.getTime() <= T2.getTime()) && (T4.getTime() >= T2.getTime()) ||
                            //判断第三种情况，第一个时间段（T1-T2）包含第二个时间段（T3-T4）
//                     T1------------------T2
//                          T3--------t4
                            (T3.getTime() >= T1.getTime() && T4.getTime() <= T2.getTime()) ||
                            //判断第四种情况，第二个时间段（T1-T2）包含第一个时间段（T3-T4）
//                          T1---------T2
//                     T3------------------t4
                            (T3.getTime() <= T1.getTime() && T4.getTime() >= T2.getTime())
                    ) {
                        sfcd = true;
                        break;
                    } else {
                       continue;
                    }
                  }
            } catch (ParseException e) {
                    e.printStackTrace();
                    }
        }
        return sfcd;
    }

    //判断当前会议室是否可用 一直用sql 查 流程结束不合理 后面查全表会越来越慢
    //应该是查 会议开始时间 大于等于 当前日期的会议流程 并且流程结束
    public boolean sqhys(String hydd,String fhykssj,String fhyjssj){
        //1.先拿到數據庫内大于等于今天日期的 并且流程结束 内 的会议开始时间 和 结束时间 的数据
        Date date = oaSpcyRsJjrkService.initializeDate(new Date()); //格式化当前日期
        String initDate = DateConversionUtils.DateToDays(date);

        List<OaHysgl> oaHysglList = oaHysglService.list(new LambdaQueryWrapper<OaHysgl>().ge(OaHysgl::getFhykssj, initDate)
                                                                                    .eq(OaHysgl::getFlczt, OaCommonFlowConstant.FLOW_LCJS)
                                                                                    .eq(OaHysgl::getFhydd,hydd));

        boolean sfcd = false;
        //2.拿到查出来的 会议开始时间 和 会议结束时间
        //遍历当前 数组 循环比较 传入的会议开始时间和会议结束时间
        if (CollectionUtil.isNotEmpty(oaHysglList)) {

            for (OaHysgl hysgl : oaHysglList) {
                //被比较的时间
//            String BjFhykssj = hysgl.getFhykssj(); //数据库中的会议开始时间
//            String BjFhyjssj = hysgl.getFhyjssj(); //数据库中会议结束时间
                //被比较的时间
                String t1 = hysgl.getFhykssj(); //拿到的数据库中的会议开始时间
                String t2 = hysgl.getFhyjssj(); //拿到的数据库中会议结束时间

                String t3 = fhykssj;
                String t4 = fhyjssj;

                DateFormat d_Fm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                try {
                    Date T1 = d_Fm.parse(t1);
                    Date T2 = d_Fm.parse(t2);
                    Date T3 = d_Fm.parse(t3);
                    Date T4 = d_Fm.parse(t4);
                    if ((
                            //T1-T2为第一个时间段  T3-T4为第二个时间段
                            //判断第一种情况，第二个时间段的结束时间T4在第一个时间段（T1-T2）内
//                          T1------T2
//                     T3--------t4
                            T3.getTime() <= T1.getTime() && T4.getTime() >= T1.getTime()) ||
                            //判断第二种情况，第二个时间段的开始时间T3在第一个时间段（T1-T2）内
//                     T1------T2
//                          T3--------t4
                            (T3.getTime() <= T2.getTime()) && (T4.getTime() >= T2.getTime()) ||
                            //判断第三种情况，第一个时间段（T1-T2）包含第二个时间段（T3-T4）
//                     T1------------------T2
//                          T3--------t4
                            (T3.getTime() >= T1.getTime() && T4.getTime() <= T2.getTime()) ||
                            //判断第四种情况，第二个时间段（T1-T2）包含第一个时间段（T3-T4）
//                          T1---------T2
//                     T3------------------t4
                            (T3.getTime() <= T1.getTime() && T4.getTime() >= T2.getTime())
                    ) {
                        sfcd = true; //表示有重叠
                        break;
                    } else {
                        continue; //表示没有重叠
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return sfcd;
    }




//    // 根据待办人id，获取名称拼接起来
//    private String getDbrsByIds(String dbrIds){
//        //把待办人按id查出来  把名字拼起来
//        String dbr = "";
//        List<String> dbrIdsList = Arrays.asList(dbrIds.split(","));
//        List<YcSysUser> sysUserList = new ArrayList<>();
//        if (CollectionUtils.isNotEmpty(dbrIdsList)) {
//            sysUserList = ycSysUserService.listByIds(dbrIdsList);
//        }
//        if (CollectionUtils.isNotEmpty(sysUserList)) {
//            for (YcSysUser user : sysUserList) {
//                dbr += user.getRealname() + ",";
//            }
//        }
//        return dbr;
//    }

//    // 会议安排负责人
//    public Map gethyapFzrByDeptName() {
//        Map map = new HashMap();
//        String dbrId = "";
//        String dbr = "";
//        List<GetKsKz> ksKzObject = new ArrayList<>();
//        ksKzObject = ycSysUserService.getKsKzObject(CommonFlowConstant.BGS_SP_FLOW, CommonFlowConstant.ROLE_NAME_HYAPFZR);
//        if (CollectionUtils.isNotEmpty(ksKzObject)) {
//            for (GetKsKz ksKz : ksKzObject) {
//                dbrId += ksKz.getId() + ",";
//                dbr += ksKz.getRealname() + ",";
//            }
//        } else {
//            throw new BusinessException("会议安排负责人不存在，请联系管理员");
//        }
//
//        map.put("dbrId", dbrId);
//        map.put("dbr", dbr);
//        return map;
//    }


//    // 对应科室的 科室负责人
//    public Map getKsfzrByDeptName(String deptName) {
//        Map map = new HashMap();
//        String dbrId = "";
//        String dbr = "";
//        List<GetKsKz> ksKzObject = new ArrayList<>();
//        ksKzObject = ycSysUserService.getKsKzObject(deptName, CommonFlowConstant.ROLE_NAME_KZ);
//        if (CollectionUtils.isNotEmpty(ksKzObject)) {
//            for (GetKsKz ksKz : ksKzObject) {
//                dbrId += ksKz.getId()+",";
//                dbr += ksKz.getRealname()+",";
//            }
//        }
//
//        map.put("dbrId",dbrId);
//        map.put("dbr",dbr);
//        return map;
//    }



//    // 获取对应科室的 分管领导
//    public Map getKsFgldByDeptName(String deptName){
//        Map map = new HashMap();
//        String dbrId = "";
//        String dbr = "";
//
//        YcSysUser fgldUserBydept = sysUserFgldService.getFgldUserBydept(deptName);
//        if (fgldUserBydept != null) {
//            dbrId = fgldUserBydept.getId();
//            dbr = fgldUserBydept.getRealname();
//        }
//
//        map.put("dbrId",dbrId);
//        map.put("dbr",dbr);
//        return map;
//    }


//    /**
//     * 将待办人map转为List
//     * @param map 待办人map
//     */
//    public List<AgentVo> getDbrListByMap(Map map){
//        String dbrids = map.get("dbrId").toString(); // 待办人id
//        String dbrs = map.get("dbr").toString(); // 待办人
//
//        List<AgentVo> agentList = new ArrayList<>();
//
//        if (org.apache.commons.lang3.StringUtils.isNotBlank(dbrids)) {
//            String agentIds[] = dbrids.split(",");
//            String agentNames[] = dbrs.split(",");
//
//            for (int i = 0; i < agentIds.length; i++) {
//                AgentVo agentVo = new AgentVo();
//                agentVo.setDbrid(agentIds[i]);
//                agentVo.setDbr(agentNames[i]);
//                agentList.add(agentVo);
//            }
//        }
//
//        return agentList;
//    }
//
//    // 对应科室的 科室负责人的id
//    public Map getKsfzrByDeptid(String deptName) {
//        Map map = new HashMap();
//        String dbrId = "";
//        String dbr = "";
//        List<GetKsKz> ksKzObject = new ArrayList<>();
//        ksKzObject = ycSysUserService.getKsKzObject(deptName, CommonFlowConstant.ROLE_NAME_KZ);
//        if (CollectionUtils.isNotEmpty(ksKzObject)) {
//            for (GetKsKz ksKz : ksKzObject) {
//                dbrId += ksKz.getId() + ",";
//            }
//        }
//        map.put("dbrId", dbrId);
//
//        return map;
//    }

//    //判断当前用户是否是科室负责人
//    public boolean brksfzr() {
//        boolean notBlank = Boolean.parseBoolean(null);
//        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
//        String nowid = currentUser.getId();
//        Map ksfzrByDeptName = getKsfzrByDeptid(currentUser.getOrgName());
//        if (currentUser != null) {
//            for (Object value : ksfzrByDeptName.values()) {
//                String valuesplit = String.join(",", (CharSequence) value);
//                int i = valuesplit.lastIndexOf(",");
//                String substring = valuesplit.substring(0, i);
//
//                notBlank = nowid.equals(substring);
//            }
//            return notBlank;
//        } else {
//            return false;
//        }
//    }


}
